package com.qf.search.config;





import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by jackiechan on 2020-02-27 09:47
 *
 * @Author jackiechan
 */
@Configuration
public class RabbitMQConfig {
    //并发的消费者的数量
    public static final int DEFAULT_CONSUMERS = 1;
    //每个消费者每次最多获取多少条消息
    public static final int DEFAULT_PREFETCH_COUNT = 50;

    @Bean
    public Queue sendLogQueue() {
        return new Queue(RabbitMqConsants.TOPIC_SMS_SEND_LOG,true);
    }

    /**
     * 并发的消费配置
     * @param configurer
     * @param connectionFactory
     * @return
     */
    @Bean("taskContainerFactory")
    public SimpleRabbitListenerContainerFactory taskContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setPrefetchCount(DEFAULT_PREFETCH_COUNT);
        factory.setConcurrentConsumers(DEFAULT_CONSUMERS);
        configurer.configure(factory, connectionFactory);
        return factory;
    }
}
